var XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;
function ajax(url) {
    const p = new Promise((resolve, reject) => {
        let xhr = new XMLHttpRequest()
        xhr.open('get', url)
        xhr.onreadystatechange = () => {
            if (xhr.readyState == 4) {
                if (xhr.status >= 200 && xhr.status <= 300) {
                    resolve(JSON.parse(xhr.responseText))
                } else {
                    reject('请求出错')
                }
            }
        }
        xhr.send()  //发送http请求
    })
    return p
}
let url = './data.json'
ajax(url).then(res => console.log(res))
    .catch(reason => console.log(reason))
